<template>
    <div>
        <el-row>
            <el-col :span="12">
                <el-table
                    ref="multipleTable"
                    :data="tableData"
                    tooltip-effect="dark"
                    @selection-change="handleSelectionChange">
                    <el-table-column
                        type="selection"
                        width="55">
                    </el-table-column>
                    <el-table-column
                        label="字段"
                        width="200">
                    <template slot-scope="scope">{{ scope.row.date }}</template>
                    </el-table-column>
                </el-table>
            </el-col>
            <el-col :span="12">
                <div style="margin-top:10px">
                  <el-checkbox-group v-model="roles">
                        <el-checkbox style="display:block;width:20%;margin-left:10px;margin-bottom:10px" label="知识之库" border></el-checkbox>
                        <el-checkbox style="display:block;width:20%;margin-bottom:10px" label="产品目录" border></el-checkbox>
                        <el-checkbox style="display:block;width:20%;margin-bottom:10px" label="系统管理" border></el-checkbox>
                        <el-checkbox style="display:block;width:20%;margin-bottom:10px" label="订单管理" border></el-checkbox>
                        <el-checkbox style="display:block;width:20%;margin-bottom:10px" label="费用预算" border></el-checkbox>
                        <el-checkbox style="display:block;width:20%;margin-bottom:10px" label="汇率管理" border></el-checkbox>
                  </el-checkbox-group>
              </div>
            </el-col>
        </el-row>
        <el-button type="primary" @click="editUser">提交</el-button>
    </div>
</template>
<script>
export default {
  data(){
      return {
          user:this.$route.params.user,
          permission:'000000000000000000000000000000000000',
          permissionObject:[],
          tableData:[],
          multipleSelection: [],
          nameList: {},
          roles:[],
          sqlNames:[
            'collectionname',
            'sku',
            'eancode',
            'desiginid',
            'supplierdesignid',
            'qualityid',
            'picture',
            'weight',
            'grossweight',
            'width',
            'height',
            'length',
            'dimensions',
            'colormap',
            'size',
            'fobpricesqm',
            'fobpricepcs','warehousecostsqm','warehousecostpcs','wholesalepricesqm',
            'wholesalepricepcs',
            'commisionsqm','commisionpcs','barcodefiles','retailprice','saleprice','material',
            'pileheight',
            'origin',
            'isburn',
            'iscolor',
            'iselectric',
            'iswater',
            'ismildew',
            'resilience',
            'nonshedding',
            'isslippery',
            'soft',
            'back',
            'iswash',
            'issmell'
        ],
          tableNames:[
            'Collection Name',
            'SKU',
            'EAN CODE',
            'Design ID',
            'Supplier Design ID',
            'Quality类别代码',
            'Picture',
            'Weight/Sqm (Kgs)',
            'Gross Weight',
            'width',
            'height',
            'length',
            'Dimensions(W*H*L) ',
            'Color Map',
            'Size',
            'FOB Price/Sqm',
            'FOB Price/PCS',
            'Warehouse Cost/SQM',
            'Warehouse Cost/PC',
            'Wholesale Prices/sqm',
            'Wholesale Prices/PCS',
            'Commision/sqm',
            'Commision/PCS',
            'Barcode Files',
            '建议零售价',
            '售价',
            'Sqm',
            'Material',
            'Pile Height',
            'Origin',
            '是否阻燃',
            '是否掉色',
            '是否防静电',
            '是否防水',
            '是否防霉',
            'Resilience(回弹性能）',
            'Non Shedding',
            '柔软舒适度',
            '背部工艺',
            '是否可水洗',
            '是否有异味'
        ],
        userPermission:[]
      }
  },
  created(){
      for(var value of this.tableNames){
          var item = {date:value};
          this.tableData.push(item);
      }
      for(var i=0;i<this.tableNames.length;i++){
          this.nameList[this.tableNames[i]] = this.sqlNames[i]
      }
  },
  methods:{
      handleSelectionChange(val) {
        this.multipleSelection = val;
      },
      editUser(){
        for(var value of this.multipleSelection){
            this.userPermission.push(this.transTo(value.date))
        }

        var params = new URLSearchParams();
        params.append('permission', this.userPermission);
        params.append('name', this.user);
        params.append('loginkey', sessionStorage.getItem('loginkey'));
        params.append('role',this.roles)
 
        this.$http.post("http://"+this.IP+"/api/setUser.php",params)
            .then((res)=>{
            //   this.taglist = res.data;
            if(res.data.code == 20000){
                this.$message.success(res.data.msg)
                this.$router.push('/admin/showUser')
            }else{
                this.$message.error(res.data.msg);
            }
        })
      },
      transTo(str){
          return this.nameList[str];
      },
  }
}
</script>
<style scoped>
</style>
